export function drawTrack (canvas, x1, y1, x2, y2, width = 15, color = '#3a3a3a') {
  let line = new fabric.Line([x1, y1, x2, y2], {
    fill: color,
    stroke: color,
    strokeWidth: width,
    selectable: false,
    lockMovementX: true,
    lockMovementY: true,
    class: 'track'
  })
  canvas.add(line)
  return line
}

export function drawTrackSleeper (canvas, x1, y1, x2, y2, width = 30, color = '#3a3a3a', timeValue = 0) {
  let sleeper = new fabric.Line([x1, y1, x2, y2], {
    fill: color,
    stroke: color,
    strokeWidth: width,
    selectable: false,
    lockMovementX: true,
    lockMovementY: true,
    class: 'sleeper'
  })
  // 添加文本
  let text = new fabric.Text('sleeper' + (x1 + timeValue), {
    left: x1 + width + 20,
    top: 250,
    fontSize: 20,
    originX: 'center', // 文本居中对齐到指定点
    originY: 'center',
    angle: -90,
    selectable: false,
    lockMovementX: true,
    lockMovementY: true,
    class: 'sleeperText'
  })
  canvas.add(text)
  canvas.add(sleeper)
}

export function drawTrackSleeper2 (canvas, x1, y1, x2, y2, width = 30, color = '#3a3a3a', timeValue = 0) {
  let sleeper = new fabric.Line([x1, y1, x2, y2], {
    fill: color,
    stroke: color,
    strokeWidth: width,
    selectable: false,
    lockMovementX: true,
    lockMovementY: true
  })
  // 添加文本
  let text = new fabric.Text('sleeper' + (timeValue), {
    left: x1 + width + 20,
    top: 250,
    fontSize: 20,
    originX: 'center', // 文本居中对齐到指定点
    originY: 'center',
    angle: -90,
    selectable: false,
    lockMovementX: true,
    lockMovementY: true
  })
  canvas.add(text)
  canvas.add(sleeper)
}
